package test.cs.purdue.edu;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

import opr.sgb.cs.purdue.edu.GroupAllOpr;
import opr.sgb.cs.purdue.edu.GroupbyOperator;
import opr.sgb.cs.purdue.edu.Iterator;

import global.sgb.cs.purdue.edu.AttrType;
import global.sgb.cs.purdue.edu.Schema;
import global.sgb.cs.purdue.edu.Tuple;
import group.cs.purdue.edu.Groups;



public class GroupAlltest extends testDriver {

	  /** Drivers table schema. */
	  private static Schema s_drivers;
	  public boolean status;
	 
	  /** The display name of the test suite. */
	  private static final String TEST_NAME = "sgb all tests";

	  
	public GroupAlltest() {
		// TODO Auto-generated constructor stub
		
		
	}
	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		GroupAlltest test=new GroupAlltest();
		 s_drivers = new Schema(3);
		 s_drivers.initField(0, AttrType.INTEGER, 4, "PKey");
		 s_drivers.initField(1, AttrType.INTEGER, 4, "x");
		 s_drivers.initField(2, AttrType.INTEGER, 4, "y");
		 
		System.out.println("\n" + "Running " + TEST_NAME + "...");
	    boolean status = PASS;
	    
	    status=status&test.test1();
	    status=status&test.test2();
	    
		}

	/**
	 * the first test case for the SGB-ALL operation
	 * @return
	 * @throws IOException
	 */
	 protected boolean test1() throws IOException {
		 boolean s1=true; 
		 
		 FileInputStream fstream = new FileInputStream(this.Stringfilename);
		 
		 DataInputStream in = new DataInputStream(fstream);
		 BufferedReader br = new BufferedReader(new InputStreamReader(in));
		 String strLine;
		 int number=0;	
		
		 //int countout=0;
		 GroupbyOperator iter= new GroupAllOpr();
		
		 int overlap=AttrType.ODUPLICATIED;
		 String indexongroups="arraylist";
		 double eps=4;
		 int []Fileds={1,2};
		 int metric=AttrType.L2;
		 
		 iter.iniEnv(metric, overlap, indexongroups, eps, Fileds);
		 
		 while ((strLine = br.readLine()) != null)   {
			   // Print the content on the console
			  Tuple tuple = new Tuple(s_drivers);
			  String items[]=strLine.split(" ");
			  tuple.setFiled(0, number);
			  
			  tuple.setFiled(1, Integer.valueOf(items[0]));
			  tuple.setFiled(2, Integer.valueOf(items[1]));
			  
			  iter.OprCurrent(tuple);
			  
			  number++;
			  if(number==9)
			  {
				  //System.out.println("error");
			  }
			
		 }
		 
		 iter.PrintOutputs();
		 
		 return s1;
		 
	 }
	 
	 protected boolean test2()
	 {
		 boolean s1=true; 
		 
		 return s1;
	 }
	 
	 
	
}
